const path = require("path")
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = {
    entry: path.resolve(__dirname, "../src/index.js"),
    output: {
        path: path.resolve(__dirname, "../build"),
        filename: "./js/main.js",
        publicPath: '/'
    },
    module: {
        rules: [
        {
            test: /\.ejs$/,
            loader: 'ejs-loader',
            options: {
                variable: 'data', // 可以在模块当中使用data进行数据处理
            }
        },{
            test: /\.css$/i,
            use: [
                //use中loader加载是有顺序的，先下后上，注意有的loader需要按照顺序书写
                "style-loader",
                'css-loader'
            ]
        }],
    },
    resolve: {
        alias: {
            $v: path.resolve(__dirname, "../src/views"),
            $r: path.resolve(__dirname, "../src/routes"),
            $a: path.resolve(__dirname, "../src/api")
        },
        //......
        // 尝试按顺序解析这些后缀名。如果有多个文件有相同的名字，但后缀名不同，webpack 会解析列在数组首位的后缀的文件 并跳过其余的后缀。
        extensions: [".js", ".json", ".ejs"],
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, "../public/index.html")
        }),
        new CopyWebpackPlugin({
            patterns: [{
                from: path.resolve(__dirname, "../public"),
                to: "public",
                globOptions: {
                    ignore: ["**/index.html"]
                }
            }],
        })
    ],
    mode: "production"
}